 /*
 * @description: 寝室视频上传列表
 * @Author: along
 * @Date: 2020-10-16 13:30:00
 * @Last Modified by: along
 * @Last Modified time: 2020-10-20
 */
<template>
    <div class="container dormVideoList">
        <!-- header -->
        <div class="header-nav">
            <div class="header-left">
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        批次组名称
                    </p>
                    <el-input
                        placeholder="请输入批次组名称"
                        v-model="formData.title"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        学校名称
                    </p>
                    <el-cascader
                        v-model="formData.school_name"
                        placeholder="请选择学校"
                        :options="school_tree"
                        filterable
                        clearable
                        size="medium"
                        expand-trigger="click"
                        @change="getTableData(1)"
                        @keyup.native.enter="getTableData(1)"
                        :props="{
                            label: 'name',
                            value: 'name',
                            children: 'children',
                            emitPath: false
                        }"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        批次组创建时间
                    </p>
                    <el-date-picker
                        v-model="dateTimeRange"
                        type="datetimerange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']"
                        size="medium"
                        style="width: 400px"
                        value-format="timestamp"
                    />
                </div>
                <!--<div class="header-new-box">
                    <p class="header-new-box-title">公司名称</p>
                    <el-select
                        v-model="formData.hire_no"
                        filterable
                        remote
                        clearable
                        size="small"
                        reserve-keyword
                        placeholder="请输入公司名称"
                        :remote-method="remoteMethod"
                        :loading="loading"
                        @change="changeShop()"
                    >
                        <el-option
                            v-for="item in suggestList"
                            :key="item.hire_no"
                            :label="item.company_name"
                            :value="item.hire_no"
                        />
                    </el-select>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">产品名称</p>
                    <el-input
                        v-model="formData.series_title"
                        placeholder="请输入产品名称"
                        size="small"
                        clearable
                        suffix-icon="el-icon-search"
                        @change="getTableData(1)"
                        @keyup.native.enter="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">视频批次:</p>
                    <el-select
                        v-model="formData.series_index"
                        clearable
                        filterable
                        placeholder="请选择"
                        size="small"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in batchList"
                            :key="item.series_index"
                            :label="item.series_index"
                            :value="item.series_index"
                        />
                    </el-select>
                </div>-->
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        @click="getTableData(1)"
                    >
                        搜索
                    </el-button>
                </div>
            </div>
            <div class="header-right">
                <div
                    class="header-new-box"
                    :style="{marginRight: '0'}"
                >
                    <!--<el-button
                        type="primary"
                        size="small"
                        @click="createBatch()"
                    >
                        新建批次
                    </el-button>-->
                </div>
            </div>
        </div>
        <!-- /header -->

        <!-- table -->
        <el-table
            :data="tableData"
            height="100%"
            style="width: 100%;"
            border
            ref="dormVideoList"
        >
            <el-table-column
                type="index"
                width="80"
                label="序号"
                align="center"
            />
            <el-table-column
                prop="title"
                label="批次组名称"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                min-width="110"
                align="left"
            />
            <el-table-column
                prop="school_name"
                label="学校"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            />
            <el-table-column
                label="寝室性别"
                show-overflow-tooltip
                align="center"
                :formatter="emptyFormatter"
            >
                <template slot-scope="scope">
                    {{ scope.row.sex === 1 ? '男' : scope.row.sex === 2 ? '女' : '不限' }}
                </template>
            </el-table-column>
            <el-table-column
                prop="video_audit_wait_count"
                label="待审核数"
                show-overflow-tooltip
                align="center"
            />
            <el-table-column
                prop="video_audit_fail_count"
                label="未通过数"
                show-overflow-tooltip
                align="center"
            />
            <el-table-column
                prop="video_audit_pass_count"
                label="已通过数"
                show-overflow-tooltip
                align="center"
            />
            <el-table-column
                prop="video_count"
                label="视频总数"
                show-overflow-tooltip
                align="center"
                :width="110"
            />
            <el-table-column
                prop="submit_audit_time"
                label="提交时间"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                :width="150"
            >
                <template slot-scope="scope">
                    {{ scope.row.submit_audit_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                </template>
            </el-table-column>
            <el-table-column
                prop="video_submit_count"
                align="center"
                label="可提审"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            />
            <el-table-column
                label="操作"
                fixed="right"
                :width="200"
            >
                <template slot-scope="scope">
                    <el-button
                        type="text"
                        class="curse-add"
                        @click="fnSubmit(scope.row)"
                        :disabled="scope.row.video_submit_count === 0"
                    >
                        提交审核
                    </el-button>
                    <!--<el-button
                        type="text"
                        class="curse-add"
                        @click="editBatch(scope.row)"
                    >
                        修改批次
                    </el-button>-->
                    <el-button
                        type="text"
                        class="curse-add"
                        @click="uploadVideo(scope.row)"
                    >
                        上传视频
                    </el-button>
                    <!--<el-button
                        type="text"
                        class="curse-add"
                        @click="fnDeleteBatch(scope.row)"
                    >
                        删除
                    </el-button>-->
                </template>
            </el-table-column>
        </el-table>
        <!-- /table -->

        <!-- /分页 -->
        <div class="pagination-wrapper clearfix">
            <el-pagination
                background
                layout="total, prev, pager, next"
                :current-page.sync="page.now_page"
                :total="page.total_count"
                :page-size="page.page_size"
                @current-change="getTableData"
            />
        </div>

        <!-- 删除弹窗 -->
        <dialog-delete
            ref="delete"
            :url="'http://cdn.zsdx.cn/phaadmin/dialog-waring.png'"
            :title="'是否确认删除?'"
            :content="'删除会影响审核数据和商家端展示的数据'"
            @confrim="confrim()"
        />

        <!-- 新建/修改-批次 -->
        <el-dialog
            :title="dialog_title"
            :visible.sync="dialogVisible"
            width="614px"
            :close-on-click-modal="false"
        >
            <div class="batch">
                <div class="batch-box">
                    <p class="batch-box-title">视频批次:</p>
                    <el-input
                        oninput="value = value.replace(/[^\d]/g,'')"
                        v-model="dialog_batch"
                        v-inserted
                        placeholder="请输入数字,记录该商家的批次"
                        size="small"
                        :disabled="dialog_title == '修改批次'"
                        :style="{width: '450px'}"
                    />
                </div>
                <div
                    class="batch-box"
                    :style="{marginTop: '24px'}"
                >
                    <p class="batch-box-title">公司名称:</p>
                    <el-select
                        v-model="dialog_user"
                        filterable
                        remote
                        size="small"
                        reserve-keyword
                        placeholder="请输入公司名称"
                        :remote-method="remoteMethod"
                        :loading="loading"
                        :style="{width: '450px'}"
                        @change="getTableData(1)"
                        :disabled="dialog_title == '修改批次'"
                    >
                        <el-option
                            v-for="item in suggestList"
                            :key="item.hire_no"
                            :label="item.company_name"
                            :value="item.hire_no"
                        />
                    </el-select>
                </div>
                <div
                    class="batch-box"
                    :style="{marginTop: '24px'}"
                >
                    <p class="batch-box-title">产品名称:</p>
                    <el-input
                        v-model="dialog_name"
                        placeholder="请输入产品名称"
                        size="small"
                        :style="{width: '450px'}"
                    />
                </div>
            </div>
            <span
                slot="footer"
                class="dialog-footer"
            >
                <el-button
                    @click="dialogVisible = false"
                    size="medium"
                    :style="{width: '120px', marginRight: '32px'}"
                >
                    取 消
                </el-button>
                <el-button
                    type="primary"
                    size="medium"
                    :disabled="!dialog_batch || !dialog_user || !dialog_name"
                    :style="{width: '120px'}"
                    @click="confirmBatch()"
                >
                    确 定
                </el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { back } from '@/mixin/back';
import dialogDelete from '@/components/dialog/index.vue';

const FILTER = {
    // hire_no: '',//公司名称
    // 批次组名称
    title: '',
    // 学校名称
    school_name: '',
    start_submit_time: '',
    end_submit_time: '',
};

const LIST = {
    ID: '',//记录唯一批次id
    batchList: [],//视频批次列表
    suggestList: [],//公司名称列表
    loading: false,
    dialog_title: '',//弹窗表头
    dialogVisible: false,//弹窗开关
};

const DIALOG = {
    dialog_batch: '',
    dialog_user: '',
    dialog_name: ''
};

export default {
    mixins: [back],
    components: { dialogDelete },
    data () {
        return {
            formData: {
                ...FILTER
            },
            ...LIST,
            ...DIALOG,
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 0
            },
            dateTimeRange: [],
            tableData: [],
            school_tree: [],
            authResult: {}
        };
    },
    filters: {},
    computed: {},
    directives: {
        inserted (el, binding, vnode, oldVnode) {
            el.addEventListener("keypress",e => {
                let event = e || window.event;
                let charcode = typeof event.charCode === 'number' ? event.charCode : event.keyCode;
                let re = /\d/;

                if(!re.test(String.fromCharCode(charcode)) && charcode > 9 && !event.ctrlKey){
                    if(event.preventDefault){
                        event.preventDefault();
                    }else{
                        event.returnValue = false;
                    }
                }
            });
        }
    },
    watch: {
        dialogVisible (val) {
            if(!val) {
                this.dialog_batch = '';
                this.dialog_user = '';
                this.dialog_name = '';
            }
        },
        dateTimeRange(value) {
            this.formData.start_submit_time = value ? value[0] / 1000 : '';
            this.formData.end_submit_time = value ? value[1] / 1000 : '';
            this.getTableData(1);
        },
    },
    mounted () {
        this.init();
    },
    methods: {
        /**
         * @description 初始化页面数据
         */
        init () {
            this.$store.commit('SET_HEADER', [{ title: "官网"},{ title: "商家增值服务"},{title: '寝室视频上传'}]);
            this.authResult = this.$route.meta.authResult;
            this.getTableData();
            this.getSuggest('');
            this.getBatchList();
            this.getSchoolTree();
        },

        /**
         * @description 获取表格数据
         */
        getTableData (page) {
            this.$post('/student/room_series%5Cget_list', {
                page_id: page || this.page.now_page,
                ...this.formData,
                is_audit: 0,
                type: 1
            }, resp => {
                if (resp.code === 1) {
                    this.tableData = resp.data.list;
                    this.page = resp.data.page;
                }
            });
        },

        /**
         * @description 获取视频批次列表/视频批次搜索
         */
        getBatchList () {
            this.$post('/student/room_series%5Cget_series_index_list', {
                keyword: '',
                hire_no: this.formData.hire_no,
                is_audit: ''
            }, resp => {
                if (resp.code == 1) {
                    this.batchList = resp.data.list;
                }
            });
        },

        /**
         * @description 获取商家列表
         */
        getSuggest (keyword) {
            this.$post('/student/room_series%5Cget_company_list', {
                keyword: keyword
            }, resp => {
                if (resp.code == 1) {
                    this.suggestList = resp.data.list;
                }
            });
        },

        /**
         * @description 获取省/市/学校三级联动
         */
        getSchoolTree () {
            this.$post('/student/local_info%5Cschool_tree',{},resp => {
                if (resp.code === 1) {
                    this.school_tree = resp.data.tree;
                }
            });
        },

        /**
         * @description 选择公司名称
         */
        changeShop () {
            this.getTableData(1);
            this.getBatchList();
        },

        /**
         * @description 新建批次
         */
        createBatch () {
            this.dialog_title = '新建批次';
            this.dialogVisible = !this.dialogVisible;
        },

        /**
         * @description 检查视频批次是否重复
         */
        // checkName (event) {
        //     let list = this.batchList.reduce((cur,next) => {
        //         cur.push(next.series_index);
        //         return cur;
        //     },[]);

        //     if(list.includes(Number(this.dialog_batch))) {
        //         this.dialog_batch = '';
        //         this.$notify({
        //             title: '提示',
        //             message: '该批次已存在,请重新填写',
        //             type: 'warning',
        //             duration: 2000
        //         });
        //     }
        // },

        /**
         * @description 新建/修改
         */
        confirmBatch () {
            if(this.dialog_title == '新建批次') {
                this.$post('/student/room_series%5Cadd',{
                    series_no: '',
                    series_index: this.dialog_batch,
                    hire_no: this.dialog_user,
                    series_title: this.dialog_name,
                    type: 1
                },resp=>{
                    if (resp.code == 1) {
                        this.dialogVisible = !this.dialogVisible;
                        this.getTableData();
                        this.$notify({
                            title: '提示',
                            message: '新建成功',
                            type: 'success',
                            duration: 2000
                        });
                    } else if (resp.code == 0) {
                        this.$notify({
                            title: '提示',
                            message: resp.msg,
                            type: 'warning',
                            duration: 2000
                        });
                    }
                });
            } else {
                this.$post('/student/room_series%5Cupdate',{
                    series_no: this.ID,
                    // series_index: this.dialog_batch,
                    // hire_no: this.dialog_user,
                    series_title: this.dialog_name,
                    type: 1
                },resp=>{
                    if (resp.code == 1) {
                        this.dialogVisible = !this.dialogVisible;
                        this.getTableData();
                        this.$notify({
                            title: '提示',
                            message: '修改成功',
                            type: 'success',
                            duration: 2000
                        });
                    } else if (resp.code == 0) {
                        this.$notify({
                            title: '提示',
                            message: resp.msg,
                            type: 'warning',
                            duration: 2000
                        });
                    }
                });
            }
        },

        /**
         * @description 修改批次
         */
        editBatch (row) {
            if(!this.authResult.auth_change) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }

            this.ID = row.series_no;
            this.dialog_batch = row.series_index;
            this.dialog_user = row.hire_no;
            this.dialog_name = row.series_title;
            this.dialog_title = '修改批次';
            this.dialogVisible = !this.dialogVisible;
        },

        /**
         * @description 搜索公司名称
         */
        remoteMethod (query) {
            if (query !== '') {
                this.loading = true;
                setTimeout(() => {
                    this.loading = false;
                    this.getSuggest(query);
                }, 200);
            }
        },

        /**
         * @description 上传视频
         */
        uploadVideo (row) {
            this.$router.push({
                name: 'dormVideoUpload',
                query: {
                    series_no: row.series_no
                }
            });
        },

        /**
         * @description 删除批次
         */
        fnDeleteBatch (row) {
            if(!this.authResult.auth_delete) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }

            this.ID = row.series_no;
            this.$refs.delete.showDialog();
        },

        /**
         * @description 确定删除
         */
        confrim () {
            this.$post('/student/room_series%5Cdelete',{
                series_no: this.ID
            },resp=>{
                if (resp.code == 1) {
                    this.getTableData();
                    this.$notify({
                        title: '提示',
                        message: '删除成功',
                        type: 'success',
                        duration: 2000
                    });
                } else if (resp.code == 0) {
                    this.$notify({
                        title: '提示',
                        message: resp.msg,
                        type: 'warning',
                        duration: 2000
                    });
                }
            });
        },

        /**
         * @description 提交审核
         */
        fnSubmit (row) {
            if(!this.authResult.auth_audit) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }

            this.$post('/student/room_series%5Csubmit_audit',{
                series_no: row.series_no
            },resp=>{
                if (resp.code == 1) {
                    this.getTableData();
                    this.$notify({
                        title: '提示',
                        message: '提交成功',
                        type: 'success',
                        duration: 2000
                    });
                } else if (resp.code == 0) {
                    this.$notify({
                        title: '提示',
                        message: resp.msg,
                        type: 'warning',
                        duration: 2000
                    });
                }
            });
        },

        /**
         * 设置表头
         */
        renderHeader (h) {
            return h('span', {}, [
                h('span', {}, '视频总数'),
                h('el-popover', { props: { placement: 'top-start', width: '200', trigger: 'hover', content: '总提交视频审核的数量，点击提交审核的数量' }}, [
                    h('i', { slot: 'reference', class:'el-icon-question'}, '')
                ])
            ]);
        },
        renderHeader2 (h) {
            return h('span', {}, [
                h('span', {}, '可提审'),
                h('el-popover', { props: { placement: 'top-start', width: '200', trigger: 'hover', content: '可提审：已经处理成功的那些数据（从“处理中”）获取； 处理中：每次上传的那些需要处理马赛克视频数量' }}, [
                    h('i', { slot: 'reference', class:'el-icon-question'}, '')
                ])
            ]);
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        }
    }
};
</script>

<style lang="less" scoped>
    .dormVideoList {
        background-color: #fff;
        display: flex;
        flex-direction: column;
        position: relative;
        width: 100%;
        box-sizing: border-box;
        padding: 24px 24px 0 24px;
        .header-nav {
            position: relative;
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            justify-content: space-between;
            .header-left, .header-right {
                display: flex;
                align-items: center;
                flex-wrap: wrap;
            }
            .header-new-box {
                display: flex;
                margin-right: 24px;
                align-items: center;
                color: #606266;
                margin-bottom: 24px;
                white-space: nowrap;
                &-title {
                    margin-right: 16px;
                    white-space: nowrap;
                }
            }
        }
        /* 表单 */
        .scope-price {
            width: 50px;
            height: 50px;
        }
        /* 字体高亮 */
        .cursor-font {
            color: rgb(64, 158, 255);
            cursor: pointer;
        }
        /* 分页 */
        .pagination-wrapper {
            padding-top: 10px;
            padding-bottom: 10px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /* 排序 */
    .sort-wrap {
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        .sort-spliter {
            width: 1px;
            height: 12px;
            background: rgba(235, 235, 235, 1);
            margin: 0 10px;
            }
            .btn-sort {
            font-size: 14px;
            line-height: 1;
            color: #ccc;
            &:hover {
                color: #20a0ff;
            }
        }
    }
    .el-button-left {
        margin-left: 40px;
    }
    .el-button-right {
        margin-right: 10px;
    }
    .audit_zero, .audit_one, .audit_err, .audit_wait {
        display: inline-block;
        width: 6px;
        height: 6px;
        border-radius: 50%;
        background: #FFAF39;
        margin-right: 6px;
        position: relative;
        top: -2px;
    }
    .audit_one {
        background: #4CD964;
    }
    .audit_err {
        background: #FF3030;
    }
    .audit_wait {
        background: #999;
    }
    .dialog-footer {
        display: flex;
        justify-content: center;
    }
    .batch {
        display: flex;
        flex-direction: column;
        &-box {
            display: flex;
            height: 32px;
            align-items: center;
            &-title {
                white-space: nowrap;
                width: 90px;
                color: #333;
            }
        }
        &-desc {
            width: 100%;
            box-sizing: border-box;
            padding-left: 75px;
            color: #999;
            font-size: 12px;
            margin-top: 5px;
            margin-bottom: 22px;
        }
    }
</style>
<style lang="less">
    .dormVideoList{
        .el-table__body-wrapper .el-table__body .el-table__row td {
            border-right: none;
        }
        .el-table__header-wrapper .el-table__header .has-gutter tr th {
            border-right: none;
        }
        .el-table .el-table_1_column_6  .cell {
            position: relative;
        }
        .el-range-editor--small .el-range-separator{
            padding: 0 1px !important;
        }
        .el-dialog__header {
            padding-top: 10px;
            box-shadow:0px 1px 0px 0px rgba(233,233,233,1);
            display: flex;
            align-items: center;
            background: #FAFAFA;
            border-radius: 4px 4px 0 0;
            .el-dialog__title {
                font-weight: 500;
                color: #333;
                font-size: 14px;
            }
            .el-icon-close:before {
                color: rgb(194,194,194);
                font-size: 17px;
                font-weight: bold;
            }
            .el-dialog__headerbtn {
                top: 14px;
            }
        }
        .el-dialog__body {
            padding-left: 80px;
            padding-right: 92px;
        }
    }
</style>
